package com.kungfuhacking.wristbandpro.login.activity;

import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.custom.InputView;
import com.kungfuhacking.wristbandpro.custom.TitleBarView;
import com.kungfuhacking.wristbandpro.login.presenter.IForgetPresenter;
import com.kungfuhacking.wristbandpro.login.view.IForgetView;


/**
 * 忘记密码
 * Created by Aaron on 17/4/17.
 */

public class ForgetActivity extends BaseActivity implements View.OnClickListener, IForgetView {

    private InputView ivaccount;
    private TextView tvgetverifycode;
    private EditText etverifycode;
    private IForgetPresenter iForgetPresenter = new IForgetPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_forget);
        initView();
    }

    private void initView() {

        Button btnnext = (Button) findViewById(R.id.btn_next);
        this.etverifycode = (EditText) findViewById(R.id.et_verify_code);
        this.tvgetverifycode = (TextView) findViewById(R.id.tv_get_verify_code);
        this.ivaccount = (InputView) findViewById(R.id.iv_account);
        TitleBarView tbv = (TitleBarView) findViewById(R.id.tbv);

        tbv.setOnLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tvgetverifycode.setOnClickListener(this);
        btnnext.setOnClickListener(this);
        ivaccount.setInputType(InputType.TYPE_CLASS_PHONE);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_get_verify_code://获取验证码
                iForgetPresenter.getSmsCode();
                break;

            case R.id.btn_next://下一步
                iForgetPresenter.nextStep();
                break;

        }
    }

    @Override
    public String getPhoneNum() {
        return ivaccount.getText();
    }

    @Override
    public String getCode() {
        return etverifycode.getText().toString();
    }

    @Override
    public void setCode(String code) {
        etverifycode.setText(code);
    }

    @Override
    public void setUnclickable() {
        tvgetverifycode.setClickable(false);
        tvgetverifycode.setEnabled(false);
    }

    @Override
    public void setClickable() {
        tvgetverifycode.setClickable(true);
        tvgetverifycode.setEnabled(true);
    }

    @Override
    public void setCountTime(String time) {
        tvgetverifycode.setText(time);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        iForgetPresenter.clearRequest();
    }
}
